<?php

/**
 * @Author: Thans
 * @Date:   2018-09-17 02:49:40
 * @Last Modified by:   Thans
 * @Last Modified time: 2018-09-19 22:38:10
 */

namespace app\admin\controller;

use app\admin\facade\UploadFile;
use app\common\controller\Admin;
use think\facade\Request;

class UploadFileController extends Admin
{
    //获取全部文件
    public function index()
    {
        $type = Request::get('type') ?: 'image';
        $page = Request::get('page') ?: '1';
        $limit = Request::get('limit') ?: '10';
        $group = Request::has('gid') ? Request::get('gid') : '-1';
        $res = UploadFile::getList($page, $limit, $type, $group);
        $this->results($res);
    }

    //移动文件到指定分组
    public function move($id)
    {
        $ids = Request::post('ids');
        if (empty($ids)) {
            $this->results(['code' => 4001, 'data' => '', 'msg' => '请选择要移动的文件']);
        } else {
            $res = UploadFile::moveByDId($ids, $id);
            $this->results($res);
        }
    }

    //批量删除
    public function deletes()
    {
        $ids = Request::post('ids');
        if (empty($ids)) {
            $this->results(['code' => 4001, 'data' => '', 'msg' => '请选择要删除的文件']);
        } else {
            $res = UploadFile::deletesByDId($ids);
            $this->results($res);
        }
    }
}
